﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web.UI;

namespace HGZP.PLL
{
    /// <summary>
    /// 功能：生成静态页
    /// 作者：许金杰
    /// 时间：2011.7.2
    /// </summary>
    public class BasePage : System.Web.UI.Page
    {
        public BasePage()
        {
        }
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            string name = Request.Url.AbsolutePath.Substring(1, Request.Url.AbsolutePath.Length - 1).Replace("aspx ", "htm ");
            string newurl = " ";
            if (name.IndexOf("/ ") > 0)
            {
                newurl = Server.MapPath("../ ") + name;
            }
            else
            {
                newurl = Server.MapPath("./ ") + name;
            }
            MemoryStream ms = new MemoryStream();
            StreamWriter sww = new StreamWriter(ms);
            StreamWriter swr = new StreamWriter(newurl);
            System.Web.UI.HtmlTextWriter htmlw = new HtmlTextWriter(swr);
            base.Render(htmlw);
            htmlw.Flush();
            htmlw.Close();
            string strLL = System.Text.Encoding.UTF8.GetString(ms.ToArray());
            Response.Write(strLL);
            Response.Redirect(Request.Url.AbsoluteUri.Replace("aspx ", "htm "), true);
        }
        /// <summary> 
        /// 传入URL返回网页的html代码 
        /// </summary> 
        /// <param name="Url">URL</param> 
        /// <returns></returns> 
        public static string getUrltoHtml(string Url)
        {
            string errorMsg = "";
            try
            {
                System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url);
                // Get the response instance. 
                System.Net.WebResponse wResp = wReq.GetResponse();
                // Read an HTTP-specific property 
                //if (wResp.GetType() ==HttpWebResponse) 
                //{ 
                //DateTime updated =((System.Net.HttpWebResponse)wResp).LastModified; 
                //} 
                // Get the response stream. 
                System.IO.Stream respStream = wResp.GetResponseStream();
                // Dim reader As StreamReader = New StreamReader(respStream) 
                System.IO.StreamReader reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("gb2312"));
                return reader.ReadToEnd();
            }
            catch (System.Exception ex)
            {
                errorMsg = ex.Message;
            }
            return "";
        }


    }

}
